class AccountingBaseElementController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        [ accountingBaseElementInstanceList: AccountingBaseElement.list( params ), accountingBaseElementInstanceTotal: AccountingBaseElement.count() ]
    }

    def show = {
        def accountingBaseElementInstance = AccountingBaseElement.get( params.id )

        if(!accountingBaseElementInstance) {
            flash.message = "AccountingBaseElement not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ accountingBaseElementInstance : accountingBaseElementInstance ] }
    }

    def delete = {
        def accountingBaseElementInstance = AccountingBaseElement.get( params.id )
        if(accountingBaseElementInstance) {
            accountingBaseElementInstance.delete()
            flash.message = "AccountingBaseElement ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "AccountingBaseElement not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def accountingBaseElementInstance = AccountingBaseElement.get( params.id )

        if(!accountingBaseElementInstance) {
            flash.message = "AccountingBaseElement not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ accountingBaseElementInstance : accountingBaseElementInstance ]
        }
    }

    def update = {
        def accountingBaseElementInstance = AccountingBaseElement.get( params.id )
        if(accountingBaseElementInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(accountingBaseElementInstance.version > version) {
                    
                    accountingBaseElementInstance.errors.rejectValue("version", "accountingBaseElement.optimistic.locking.failure", "Another user has updated this AccountingBaseElement while you were editing.")
                    render(view:'edit',model:[accountingBaseElementInstance:accountingBaseElementInstance])
                    return
                }
            }
            accountingBaseElementInstance.properties = params
            if(!accountingBaseElementInstance.hasErrors() && accountingBaseElementInstance.save()) {
                flash.message = "AccountingBaseElement ${params.id} updated"
                redirect(action:show,id:accountingBaseElementInstance.id)
            }
            else {
                render(view:'edit',model:[accountingBaseElementInstance:accountingBaseElementInstance])
            }
        }
        else {
            flash.message = "AccountingBaseElement not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def accountingBaseElementInstance = new AccountingBaseElement()
        accountingBaseElementInstance.properties = params
        return ['accountingBaseElementInstance':accountingBaseElementInstance]
    }

    def save = {
        def accountingBaseElementInstance = new AccountingBaseElement(params)
        if(!accountingBaseElementInstance.hasErrors() && accountingBaseElementInstance.save()) {
            flash.message = "AccountingBaseElement ${accountingBaseElementInstance.id} created"
            redirect(action:show,id:accountingBaseElementInstance.id)
        }
        else {
            render(view:'create',model:[accountingBaseElementInstance:accountingBaseElementInstance])
        }
    }
}
